﻿@model JRFinances.ViewModels.VirtualTransactions.CreateVirtualTransactionViewModel

<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>

@using (Html.BeginForm()) {
    @Html.ValidationSummary(true)
    <fieldset>
        <legend>Nowa wirtualna transakcja kupna</legend>

        <div class="editor-label">
            @Html.LabelFor(model => model.CompanyId, "Spolka")
        </div>
        <div class="editor-field">
            @Html.DropDownList("CompanyId", String.Empty)
            @Html.ValidationMessageFor(model => model.CompanyId)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.Date)
        </div>
        <div class="editor-field">
            @Html.DisplayFor(model => model.Date, new {  @readonly = "readonly" })
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.Volume)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Volume)
            @Html.ValidationMessageFor(model => model.Volume)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.Price)
        </div>
        <div class="editor-field disabled_input">
            @Html.TextBoxFor(model => model.Price, new { @readonly = "readonly" })
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.CurrentSaldo)
        </div>
        <div class="editor-field">
            @Html.DisplayFor(model => model.CurrentSaldo)
        </div>
        @Html.HiddenFor(model => model.Price)
        @Html.HiddenFor(model => model.Buy)
        @Html.HiddenFor(model => model.CurrentSaldo)

        <p>
            <input type="submit" value="Dodaj" />
        </p>
    </fieldset>
}

<div>
    @Html.ActionLink("Powrot do listy", "ShowCurrentlyOwnedShares")
</div>

<script>
    $('#CompanyId').change(function () {
        var selectedProposal = $(this).val();
        $.ajax({
            url: '/VirtualTransactions/GetPriceForCompany/',
            type: 'GET',
            traditional: true,
            data: { id: selectedProposal },
            dataType: 'text',
            success: function (data) {
                $('#Price').val(data);
            }
        });
    });</script>